package org.bluweb.g4wicket.search;

import java.util.HashMap;
import java.util.Map;

import org.bluweb.g4wicket.G4WicketComponent;
import org.bluweb.g4wicket.G4WicketEvent;


@SuppressWarnings("serial")
public class SearchControl extends G4WicketComponent {

	private String initialSearch = "";
	
	public SearchControl( String id ) {
		super( id );
	}
	
	@Override
	protected void onBeforeRender() {
		super.onBeforeRender();
		
		Map<String,Object> parameters = new HashMap<String,Object>();
		parameters.put( "id", this.getMarkupId() );
		parameters.put( "initialSearch", initialSearch );
		
		this.setJavaScriptTemplate( "SearchControl.js", true, parameters );
	}
	
	public SearchControl setInitialSearch( String search ) {
		this.initialSearch = search;
		return this;
	}
	
	public void execute( String search, G4WicketEvent event ) {

		super.execute( this.getMarkupId() + ".execute('" + search + "')", event );
	}
}
